/*!
 * login.js
 */
(function ($) {
    // Register
    $('.btn-register').click(function (e) {
        e.preventDefault();
        var $form = $('#UserRegisterForm');
        $.post('/users/register', $form.serialize(), function (result) {
            if (result.status) {
                layer.msg(result.info, {icon: 1});
            } else {
                layer.msg(result.info, {icon: 2});
            }
        }, 'json');
        setTimeout(function () {
            window.location.href = '/users/login';
        }, 2000);
    });

    // Login
    $('.btn-login').click(function (e) {
        e.preventDefault();
        var $form = $('#UserLoginForm');
        $.post('/users/login', $form.serialize(), function (result) {
            if (result.status) {
                layer.msg(result.info, {icon: 1});
                setTimeout(function () {
                    window.location.href = result.url;
                }, 2000);
            } else {
                layer.msg(result.info, {icon: 2});
            }
        }, 'json');
    });
})(window.jQuery);
